package runesim.shared;
import org.xsocket.connection.*;
/**
 * Manages all current connections to this server socket using NIO.
 * 
 * @author Ben
 */
public class ConnectionManager {
	
	/**
	 * Create the connection manager with specified socket port to bind on.
	 * 
	 * @param port
	 *            Server socket port to bind with.
	 */
	public ConnectionManager(int port) {
		this.port = port;
	}
	
	public void bind(org.xsocket.connection.IDataHandler what) {
		try {
			IServer server = new org.xsocket.connection.Server(getPort(), what);
			ConnectionUtils.start(server);
		} catch(Exception e) {
			System.out.println("Socket failed to bind to address on " + getPort());
			e.printStackTrace();
		}
	}
	
	public boolean isHostBlocked(String s) {
		// TODO Host lookup with login server or other
		return false;
	}
	
	/**
	 * Get the port this ConnectionManager is bound to.
	 * 
	 * @return The port this connection will use.
	 */
	public int getPort() {
		return port;
	}
	
	/**
	 * The port which has been specified to bind to.
	 */
	private int port;
}
